package day240602;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class MapDemo {
    public static void main(String[] args) {
        // 回顾之前泛型时候写的 day240522.MyMap<K, V>
        HashMap<String, Integer> group = new HashMap<>();
        group.put("第一组", 3);
        group.put("第二组", 4);
        System.out.println(group);
        System.out.println(group.toString());
        // 根据 key 获取 value
        System.out.println(group.get("第一组"));
        // 验证 map 的 key 不能重复 =》 Set 的特性
        group.put("第一组", 30);
        group.put("第一组", 38);
        System.out.println(group.get("第一组"));

        System.out.println("=== === ===");

        Set<Map.Entry<String, Integer>> entries = group.entrySet();
        Iterator<Map.Entry<String, Integer>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Integer> next = iterator.next();
            System.out.println(next.getKey() + "===" + next.getValue());
        }
        System.out.println("--- --- ---");
        Iterator<Map.Entry<String, Integer>> i = group.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry<String, Integer> next = i.next();
            System.out.println(next.getKey() + ",,," + next.getValue());
        }
    }
}
